<?php
/**
 * Created by PhpStorm.
 * User: zhangyurong
 * Date: 2016/8/26
 * Time: 17:41
 */
namespace App\Http\Controllers\Common\English;

use App\Models\Common\CollCategory;
use App\Models\Common\English\EnCollOption;

use App\Facades\Style;
use App\Http\Controllers\Common\CommonController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;


class OptionController extends CommonController{
    protected $optionAll=array(
            'company'=>array('language','comkind','monthlypay','work_year','industry','employee_num','education','part_status'),
            'personal'=>array('education','language','ComputerAbility','work_year','speciality','job_status','marital','expectedsalary','degree','title'),
            'resume'=>array('language','comkind','monthlypay','work_year','industry','employee_num','education','language','ComputerAbility',
            'speciality','job_status','marital','expectedsalary','degree','title'),
            'jobsearch'=>array('industry','work_year','education','release_date'),
            'comsearch'=>array('work_year','education','age_stint','release_date'),
            'my_resume'=>array('education','job_status','expectedsalary','release_date','marital'),
    );
    /**
     * @param $sign
     * @return \Illuminate\Http\JsonResponse
     * 说明:打印json
     */
    public function json($sign){
        $option=EnCollOption::getOption($sign);
        return response()->json($option);
    }

    /**
     * @param $sign
     * @return string
     */
    public function js($sign){
        if (Cache::has('option-'.$sign)) {
            $value = Cache::get('option-'.$sign);
        }else{
            $jsstr='';$arr=array();
            if(substr($sign,0,5)=='all--' and substr($sign,5)!=''){
                if(!empty($this->optionAll[substr($sign,5)])){
                    $arr=$this->optionAll[substr($sign,5)];
                }
            }elseif(substr($sign,0,5)=='all--'){
                $allarray=CollCategory::all();
                foreach($allarray as $value){
                    $arr[]=$value['sign'];
                }
            }else{
                $arr = explode("-",$sign);
            }
            foreach($arr as $v){
                $option=EnCollOption::getOption($v);//
                $option=json_encode($option);
                //print_r($option);exit;
                if($option!='[]') $jsstr.='var option_'.$v.'='.$option.';';//把json转成字符串拼接万js代码
            }
            $value= $jsstr?$jsstr:'';
            if($value) Cache::forever('option-'.$sign, $value);
        }
        return $value?$value:"var error_option= 'There is no corresponding option!';";
    }
}